package leetcode2;

public class LeetCodeMain129 {
    //滑动窗口
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int ans=0;
        int l=0;
        int r=0;
        int cur=1;
        while (l<=r&&r<nums.length){
            cur*=nums[r];
            while (l<=r&&cur>=k){
                cur/=nums[l];
                l++;
            }
            ans+=(r-l+1);
            r++;
        }
        return ans;
    }
    //暴力
    public int numSubarrayProductLessThanK1(int[] nums, int k) {
        int maxNum=0;
        for (int i = 0; i < nums.length; i++) {
            int sum=nums[i];
            if (sum<k){
                maxNum++;
            }
            for (int j = i+1; j < nums.length; j++) {
                sum*=nums[j];
                if (sum<k){
                    maxNum++;
                }else {
                    break;
                }
            }
        }
        return maxNum;
    }
}